# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=ruby-rbtree
_pkgname="${pkgname#ruby-}"
pkgver=0.4.6
pkgrel=1
pkgdesc='A sorted associative collection that is implemented with a Red-Black Tree'
arch=('loong64' 'x86_64')
url='https://rubygems.org/gems/rbtree'
license=('MIT')
depends=('ruby')
options=('!emptydirs')
source=("$pkgname-$pkgver.gem::https://rubygems.org/downloads/$_pkgname-$pkgver.gem")
noextract=("$pkgname-$pkgver.gem")
b2sums=('cd44852f8de9138d9f590825c62b1863e8a4fc51a3f150317f929e200430b9a4fcc7f7b83deb0904def84cfe3debf102e7b200fe1e894422b0515297ed44baff')

package() {
  local _gemdir="$(gem env gemdir)"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "$pkgdir/$_gemdir" \
    --bindir "$pkgdir/usr/bin" \
    "$pkgname-$pkgver.gem"

  # delete unnecessary files/folders
  rm -rf "$pkgdir/$_gemdir/cache"
  find "$pkgdir" -type f -name '*.o' -delete
  rm -rf "$pkgdir/$_gemdir/gems/$_pkgname-$pkgver/$_pkgname.so"

  # license
  install -vd "$pkgdir/usr/share/licenses/$pkgname"
  ln -sf "$_gemdir/gems/$_pkgname-$pkgver/LICENSE" "$pkgdir/usr/share/licenses/$pkgname"
}
